docs/html/hcall: Hypercall docs headers
cover docs/html/hcall: Hypercall docs headers
This is my proposed approach to providing hypercall documentation: we provide an htmlified copy of the xen public headers, with a contents page and cross-reference hyperlinks added.
This is done by a 350-line Perl script to which we can add features as we think of them.
An example of the output can be found here:
http://www.chiark.greenend.org.uk/~ijackson/volatile/2011/xen/hcall/
PATCH 1/4 docs/html/hcall: Initial cut of header documentation massager
"xen-headers" generates HTML from header files. So far this generates just some type cross-references, if you say
make -C docs html/hcall/stamp
An index page, proper wiring into the build system, and a few more annotations in the headers, and will be forthcoming.
--- docs/Makefile | 8 ++ docs/xen-headers | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 289 insertions(+), 0 deletions(-) create mode 100755 docs/xen-headers
docs/Makefile +8 -0
@@ -129,6 +129,14 @@ html/%.html: %.markdown $(MARKDOWN) $< > [email protected] ; \ $(call move-if-changed,[email protected],$@) ; fi +html/hcall/stamp: + @$(INSTALL_DIR) $(@D) + ./xen-headers -O $(@D) \ + -T 'arch-x86_64 - Xen public headers' \ + -X arch-ia64 -X arch-x86_32 -X xen-x86_32 \ + ../xen include/public + touch $@ + txt/%.txt: %.txt $(INSTALL_DIR) $(@D) cp $< [email protected]
docs/xen-headers new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 1/4] docs/html/hcall: Initial cut of header documentation massager
Quoted 39 lines · Ian Jackson
"xen-headers" generates HTML from header files. So far this generates just some type cross-references, if you say
make -C docs html/hcall/stampAn index page, proper wiring into the build system, and a few more annotations in the headers, and will be forthcoming.
Signed-off-by Ian Jackson <[email protected]>--- docs/Makefile | 8 ++ docs/xen-headers | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 289 insertions(+), 0 deletions(-) create mode 100755 docs/xen-headersdocs/Makefile +8
-0@@ -129,6 +129,14 @@ html/%.html: %.markdown $(MARKDOWN) $< > [email protected] ; \ $(call move-if-changed,[email protected],$@) ; fi +html/hcall/stamp: + @$(INSTALL_DIR) $(@D) + ./xen-headers -O $(@D) \ + -T 'arch-x86_64 - Xen public headers' \ + -X arch-ia64 -X arch-x86_32 -X xen-x86_32 \ + ../xen include/public + touch $@ + txt/%.txt: %.txt $(INSTALL_DIR) $(@D) cp $< [email protected]docs/xen-headers new file +0
-0
docs/xen-headers line 3
Quoted 3 lines
docs/xen-headers new file +3
-0@@ -0,0 +1,281 @@ +#!/usr/bin/perl -w +# usage: xen-headers [ -X GLOB -I GLOB ... [-D...] ] \ +# -O HTML-DIR PUBLIC-INCLUDE-DIR
No "-T"? Also for PUBLIC-INCLUDE-DIR you appear to pass "../xen include/public" so my guess is that it is slightly more complicated? Looks like "BASE-PUBLIC-INCLUDE-DIR PUBLIC-INCLUDE-FILE
[ PUBLIC-INCLUDE-FILE ... ]
[...]
docs/xen-headers line 201
Quoted 3 lines
docs/xen-headers new file +3
-0+ s/\&/\&/g; + s/\</\</g; + s/\>/\>/g;
There must be a perl lib for this?
Ian.
Re: [PATCH 1/4] docs/html/hcall: Initial cut of header documentation massager
Ian Campbell writes ("Re: [Xen-devel] [PATCH 1/4] docs/html/hcall: Initial cut of header documentation massager"):
Quoted 7 lines · Ian Jackson
Quoted 6 lines
docs/xen-headers new file +0
-0@@ -0,0 +1,281 @@
Quoted 8 lines
docs/xen-headers line 3
Quoted 3 lines
docs/xen-headers new file +3
-0+#!/usr/bin/perl -w +# usage: xen-headers [ -X GLOB -I GLOB ... [-D...] ] \ +# -O HTML-DIR PUBLIC-INCLUDE-DIRNo "-T"? Also for PUBLIC-INCLUDE-DIR you appear to pass "../xen
include/public" so my guess is that it is slightly more complicated? Looks like "BASE-PUBLIC-INCLUDE-DIR PUBLIC-INCLUDE-FILE
[ PUBLIC-INCLUDE-FILE ... ]
I seem to have forgotten to update the usage comment there. I will fix this.
Quoted 6 lines
[...]
docs/xen-headers line 201
Quoted 3 lines
docs/xen-headers new file +3
-0+ s/\&/\&/g; + s/\</\</g; + s/\>/\>/g;There must be a perl lib for this?
Yes, but it's not in the base perl distribution and I didn't want to pull in a dependent library for three trivial lines.
Ian.
PATCH 2/4 docs/html/hcall: Annotations for two hypercalls
In reply to Ian JacksonAdd annotations for a couple of the hypercalls:
HYPERVISOR_set_trap_table
HYPERVISOR_mmu_update
We do this by
* annotating the list of #defines for hypercall numbers
* annotating the list of error values
* providing a function prototype for the systematically-named functions
The header generator does the rest.
This exercise revealed a couple of infelicities:
* In the actual source code, do_mmu_update is defined to return an int and do_set_trap_table a long. However both functions return either -Efoo (on error) or 0 for success.
* The error numbers are defined only in the private header file xen/include/xen/errno.h and then only with names which will typically clash with other projects. It would be nice to include a public version of this header which defines XEN_E*. But for now we run xen-headers on errno.h too.
--- docs/Makefile | 2 +- xen/include/public/arch-x86/xen.h | 6 ++++++ xen/include/public/xen.h | 11 +++++++++-- xen/include/xen/errno.h | 5 +++++ 4 files changed, 21 insertions(+), 3 deletions(-)
docs/Makefile +1 -1
@@ -134,7 +134,7 @@ html/hcall/stamp: ./xen-headers -O $(@D) \ -T 'arch-x86_64 - Xen public headers' \ -X arch-ia64 -X arch-x86_32 -X xen-x86_32 \ - ../xen include/public + ../xen include/public include/xen/errno.h touch $@ txt/%.txt: %.txt
xen/include/public/arch-x86/xen.h +6 -0
@@ -82,7 +82,13 @@ typedef unsigned long xen_pfn_t;typedef unsigned long xen_ulong_t ;/* +* ` enum neg_errnoval +* ` HYPERVISOR_set_trap_table(const struct trap_info traps[]); +* ` +*/ +/* * Send an array of these to HYPERVISOR_set_trap_table(). +* Terminate the array with a sentinel entry, with traps[].address==0. * The privilege level specifies which modes may enter a trap via a software * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate * privilege levels as follows:
xen/include/public/xen.h +9 -2
@@ -55,6 +55,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);* HYPERCALLS */ +/* ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*() */ +#define __HYPERVISOR_set_trap_table 0#define __HYPERVISOR_mmu_update 1#define __HYPERVISOR_set_gdt 2
@@ -105,6 +107,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define __HYPERVISOR_arch_6 54#define __HYPERVISOR_arch_7 55 +/* ` } */ +/* * HYPERCALL COMPATIBILITY. */
@@ -163,8 +167,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define NR_VIRQS 24/* -* HYPERVISOR_mmu_update(reqs, count, pdone, foreigndom) -* +* ` enum neg_errnoval +* ` HYPERVISOR_mmu_update(const struct mmu_update reqs[], +* ` unsigned count, unsigned *done_out, +* ` unsigned foreigndom) +* ` * @reqs is an array of mmu_update_t structures ((ptr, val) pairs). * @count is the length of the above array. * @pdone is an output parameter indicating number of completed operations
xen/include/xen/errno.h +5 -0
@@ -1,6 +1,9 @@#ifndef _I386_ERRNO_H#define _I386_ERRNO_H +/* ` enum neg_errnoval { /* -Efoo for each Efoo in the list below } */ +/* ` enum errnoval { */ +#define EPERM 1/* Operation not permitted */ #define ENOENT 2/* No such file or directory */ #define ESRCH 3/* No such process */
@@ -129,4 +132,6 @@#define ENOMEDIUM 123/* No medium found */ #define EMEDIUMTYPE 124/* Wrong medium type */ +/* } */ +#endif
Signature · 1 line
1.7.2.5
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
xen/include/xen/errno.h line 4
Quoted 9 lines · Ian Jackson
xen/include/xen/errno.h +1
-0@@ -1,6 +1,9 @@#ifndef _I386_ERRNO_H#define _I386_ERRNO_H +/* ` enum neg_errnoval { /* -Efoo for each Efoo in the list below } */
Do we pass -Wcomment (or something which includes it)? If so gcc might warn:
/home/ianc/t.c:5:26: warning: "/*" within comment
(and we use -Werror, so...).
Is this syntax trying to encode some meaning or was it just a typo?
xen/include/xen/errno.h line 135
Quoted 10 lines
xen/include/xen/errno.h +3
-0+/* ` enum errnoval { */ +#define EPERM 1/* Operation not permitted */ #define ENOENT 2/* No such file or directory */ #define ESRCH 3/* No such process */ @@ -129,4 +132,6 @@#define ENOMEDIUM 123/* No medium found */ #define EMEDIUMTYPE 124/* Wrong medium type */ +/* } */
Is the ` supposed to be required here or is omitting it fine?
Quoted 2 lines
xen/include/xen/errno.h +1
-0+#endif
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
Ian Campbell writes ("Re: [Xen-devel] [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls"):
Quoted 7 lines · Ian Jackson
Quoted 1 line
+/* ` enum
neg_errnoval{ /* -Efoo for each Efoo in the list below } */Do we pass -Wcomment (or something which includes it)? If so gcc might warn:
/home/ianc/t.c:5:26: warning: "/*" within comment(and we use -Werror, so...).
Good point. I don't think we pass that now - I would have noticed. But we probably should do so I should change the comment there to [ ] or something.
Quoted 1 line
Is this syntax trying to encode some meaning or was it just a typo?
Ideally it would have had a matching */ but obv. that wouldn't have worked :-).
Quoted 9 lines
Quoted 9 lines
xen/include/xen/errno.h +2
-0+/* ` enum errnoval { */ +#define EPERM 1/* Operation not permitted */ #define ENOENT 2/* No such file or directory */ #define ESRCH 3/* No such process */ @@ -129,4 +132,6 @@#define ENOMEDIUM 123/* No medium found */ #define EMEDIUMTYPE 124/* Wrong medium type */
Quoted 3 lines
xen/include/xen/errno.h line 135
Quoted 1 line
xen/include/xen/errno.h +1
-0+/* } */ Is the ` supposed to be required here or is omitting it fine?
Omitting the ` means the processor doesn't see that which means the remaining #defines in that file would count as part of the enum - except there aren't any. So it's a bug.
Ian.
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
In reply to Ian JacksonQuoted 3 lines · Ian Jackson
Add annotations for a couple of the hypercalls:
HYPERVISOR_set_trap_table
HYPERVISOR_mmu_update
So I've some comments on the affects of what this hypercall expects in some details. Where would I put those? In the header file or should I do it somewhere else?
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
Konrad Rzeszutek Wilk writes ("Re: [Xen-devel] [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls"):
Quoted 8 lines · Ian Jackson
Quoted 3 lines
Add annotations for a couple of the hypercalls:
HYPERVISOR_set_trap_table
HYPERVISOR_mmu_updateSo I've some comments on the affects of what this hypercall expects in some details. Where would I put those? In the header file or should I do it somewhere else?
In the header file.
Ian.
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
Quoted 11 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("Re: [Xen-devel] [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls"):
Quoted 8 lines · Ian Jackson
Quoted 3 lines
Add annotations for a couple of the hypercalls:
HYPERVISOR_set_trap_table
HYPERVISOR_mmu_updateSo I've some comments on the affects of what this hypercall expects in some details. Where would I put those? In the header file or should I do it somewhere else?
In the header file.
Is it OK if it runs on for pages?
Re: [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls
Konrad Rzeszutek Wilk writes ("Re: [Xen-devel] [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls"):
Quoted 7 lines · Ian Jackson
Quoted 6 lines
Konrad Rzeszutek Wilk writes ("Re: [Xen-devel] [PATCH 2/4] docs/html/hcall: Annotations for two hypercalls"):
Quoted 5 lines · Ian Jackson
Quoted 3 lines
Add annotations for a couple of the hypercalls:
HYPERVISOR_set_trap_table
HYPERVISOR_mmu_update
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So I've some comments on the affects of what this hypercall expects in some details. Where would I put those? In the header file or should I do it somewhere else?
In the header file.
Is it OK if it runs on for pages?
Yes. See also the approach we're taking in libxl.h.
If it really gets too long you can take it out and put it in a text or markdown or pod file in docs/, leaving behind a reference.
Ian.
PATCH 3/4 docs/html/hcall: Generate an "index.html"
In reply to Ian JacksonGenerate an "index.html" containing various useful links.
--- docs/xen-headers | 55 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/public/xen.h | 4 ++- 2 files changed, 58 insertions(+), 1 deletions(-)
docs/xen-headers +55 -0
@@ -50,6 +50,8 @@ my ($basedir,@indirs) = @ARGV; # general globals our $pass; our %sdef; +our @incontents; +our @outfiles; # $sdef{$type}{$name} => { # DefLocs => { "$leaf_path:$lineno" => $leaf_opath ,... } # Xrefs => { "$leaf_path,$lineno" => "$xref", ... }
@@ -177,6 +179,19 @@ sub out_xrefs ($) { @pending_xrefs = (); } +sub incontents ($$$) { + my ($text, $seq, $anchor) = @_; + $anchor = "incontents_$anchor"; + if ($pass==2) { + push @incontents, { + Seq => $seq, + Href => "$leaf_opath#$anchor", + Title => $text, + }; + } + return "<a name=\"$anchor\"><strong>$text</strong></a>"; +} + sub write_file ($$) { my ($opath, $odata) = @_; my $out = new IO::File "$opath.new", '>' or die "$opath $!";
@@ -231,6 +246,8 @@ sub process_file ($$) { } } elsif (s/^( \s* \#define \s+ ) (\w+) ( \s+\S ) / $1.defmacro($2).norm($3) /xe) { + } elsif (s/( \`incontents \s+ (\d+) \s+ (\w+) \s+ )(\S .* \S) + / norm($1).incontents($4, $2, $3) /xe) { } else { if (m/^\s*\}/) { $in_enum = undef;
@@ -250,11 +267,47 @@ sub process_file ($$) { warning("pending xrefs at end of file") if @pending_xrefs; if ($pass == 2) { + push @outfiles, [ $leaf, $leaf_opath ]; $o .= "</pre></body></html>"; write_file($outfile, $o); } } +sub output_index () { + my $title = "contents - $xtitle"; + $o = ''; + $o .= <<END; +<html><head><title>$title</title></head> +<body> +<h1>$title</h1> +<h2>Starting points</h2> +<ul> +END + foreach my $ic (sort { $a->{Seq} <=> $b->{Seq} } @incontents) { + $o .= "<li><a href=\"$ic->{Href}\">$ic->{Title}</a></li>\n"; + } + $o .= "</ul>\n"; + my $forkind = sub { + my ($type,$desc,$pfx,$sfx) = @_; + $o .= "<h2>$desc</h2><ul>\n"; + foreach my $name (sort keys %{ $sdef{$type} }) { + my $href = refhref($type,$name); + next unless $href =~ m/\S/; + $o .= "<li><a $href>$pfx$name$sfx</a></li>\n"; + } + $o .= "</ul>\n"; + }; + $forkind->('Func','Functions','','()'); + $forkind->('Struct','Structs','struct ',''); + $forkind->('Enum','Enums and sets of #defines','',''); + $forkind->('EnumVal','Enum values and individual #defines','',''); + $o .= "</ul>\n<h2>Files</h2><ul>\n"; + foreach my $of (sort { $a->[0] cmp $b->[0] } @outfiles) { + $o .= "<li><a href=\"$of->[1]\">$of->[0]</a></li>\n"; + } + $o .= "</ul></body></html>\n"; + write_file("$outdir/index.html", $o); +} foreach $pass (qw(1 2)) { find({ wanted =>
@@ -279,3 +332,5 @@ foreach $pass (qw(1 2)) { }, map { "$basedir/$_" } @indirs); } + +output_index();
xen/include/public/xen.h +3 -1
@@ -55,7 +55,9 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);* HYPERCALLS */ -/* ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*() */ +/* `incontents 100 hcalls List of hypercalls +* ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*() +*/ #define __HYPERVISOR_set_trap_table 0#define __HYPERVISOR_mmu_update 1
Signature · 1 line
1.7.2.5
Re: [PATCH 3/4] docs/html/hcall: Generate an "index.html"
docs/xen-headers sub process_file ($$) { · line 250
Quoted 6 lines · Ian Jackson
docs/xen-headers +2
-0@@ -231,6 +246,8 @@ sub process_file ($$) { } } elsif (s/^( \s* \#define \s+ ) (\w+) ( \s+\S ) / $1.defmacro($2).norm($3) /xe) { + } elsif (s/( \`incontents \s+ (\d+) \s+ (\w+) \s+ )(\S .* \S) + / norm($1).incontents($4, $2, $3) /xe) {
You had a comment describing the syntax which I don't think includes this bit.
Re: [PATCH 3/4] docs/html/hcall: Generate an "index.html"
Ian Campbell writes ("Re: [Xen-devel] [PATCH 3/4] docs/html/hcall: Generate an "index.html""):
Quoted 10 lines · Ian Jackson
docs/xen-headers sub process_file ($$) { · line 250
Quoted 6 lines
docs/xen-headers +2
-0@@ -231,6 +246,8 @@ sub process_file ($$) { } } elsif (s/^( \s* \#define \s+ ) (\w+) ( \s+\S ) / $1.defmacro($2).norm($3) /xe) { + } elsif (s/( \`incontents \s+ (\d+) \s+ (\w+) \s+ )(\S .* \S) + / norm($1).incontents($4, $2, $3) /xe) {You had a comment describing the syntax which I don't think includes this bit.
Good point.
Ian.
PATCH 4/4 docs/html/hcall: Arrange for automatic build
In reply to Ian Jackson- Use index.html rather than a stamp file.
- Automatically generate dependencies.
- Wire into the docs build system
--- docs/Makefile | 9 ++++++--- docs/xen-headers | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-)
docs/Makefile +6 -3
@@ -15,7 +15,8 @@ DOC_MARKDOWN := $(wildcard misc/*.markdown) DOC_PS := $(patsubst src/%.tex,ps/%.ps,$(DOC_TEX)) DOC_PDF := $(patsubst src/%.tex,pdf/%.pdf,$(DOC_TEX)) DOC_HTML := $(patsubst src/%.tex,html/%/index.html,$(DOC_TEX)) \ - $(patsubst %.markdown,html/%.html,$(DOC_MARKDOWN)) + $(patsubst %.markdown,html/%.html,$(DOC_MARKDOWN)) \ + html/hcall/index.html DOC_TXT := $(patsubst %.txt,txt/%.txt,$(wildcard misc/*.txt)) \ $(patsubst %.markdown,txt/%.txt,$(DOC_MARKDOWN))
@@ -129,13 +130,15 @@ html/%.html: %.markdown $(MARKDOWN) $< > [email protected] ; \ $(call move-if-changed,[email protected],$@) ; fi -html/hcall/stamp: +html/hcall/index.html: ./xen-headers + rm -rf $(@D) @$(INSTALL_DIR) $(@D) ./xen-headers -O $(@D) \ -T 'arch-x86_64 - Xen public headers' \ -X arch-ia64 -X arch-x86_32 -X xen-x86_32 \ ../xen include/public include/xen/errno.h - touch $@ + +-include html/hcall/.deps txt/%.txt: %.txt $(INSTALL_DIR) $(@D)
docs/xen-headers +14 -0
@@ -310,6 +310,12 @@ END } foreach $pass (qw(1 2)) { + my $depspath = "$outdir/.deps"; + my $depsout; + if ($pass==2) { + $depsout = new IO::File "$depspath.new", 'w' or die $!; + } + find({ wanted => sub { return unless m/\.h$/;
@@ -326,11 +332,19 @@ foreach $pass (qw(1 2)) { $leaf_opath = $leaf; $leaf_opath =~ s#/#,#g; $leaf_opath .= ".html"; + print $depsout "$outdir/index.html: $File::Find::name\n" + or die $! + if $pass==2; process_file($File::Find::name, $outdir.'/'.$leaf_opath); }, no_chdir => 1, }, map { "$basedir/$_" } @indirs); + + if ($pass==2) { + close $depsout or die $!; + rename "$depspath.new", "$depspath" or die $!; + } } output_index();
Signature · 1 line
1.7.2.5
Quoted 9 lines · Ian Jackson
This is my proposed approach to providing hypercall documentation: we provide an htmlified copy of the xen public headers, with a contents page and cross-reference hyperlinks added.
This is done by a 350-line Perl script to which we can add features as we think of them.
An example of the output can be found here:
http://www.chiark.greenend.org.uk/~ijackson/volatile/2011/xen/hcall/
Excellent stuff.
It seems to consider
static struct xsd_errors xsd_errors[]
#if defined(__GNUC__)
__attribute__((unused))as defining a function called __attribute__ which is a bit unfortunate!
I had some nitpicks as I looked over the patches but regardless I think this is a good start and should go in. All:
Ian.
Ian Campbell writes ("Re: [Xen-devel] [PATCH 0/4] docs/html/hcall: Hypercall doc> Excellent stuff.
Glad you like it.
Quoted 5 lines
It seems to consider
static struct xsd_errors xsd_errors[] #if defined(__GNUC__) __attribute__((unused))as defining a function called
__attribute__which is a bit unfortunate!
I can fix that easily enough by special-casing keywords.
Quoted 3 lines
I had some nitpicks as I looked over the patches but regardless I think this is a good start and should go in. All:
Acked-by Ian Campbell <[email protected]>
Thanks.
Ian.